/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package client.core;

import proprietes.ConnectProprietes;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * 
 * @author User
 */
public class Conect{
	Socket clientSocket = null;
	PrintStream os = null;
	BufferedReader is = null;
	BufferedReader inputLine = null;

	public String createConection() {
		{
			try {
				clientSocket = new Socket(ConnectProprietes.SERVER.getValue(),
						ConnectProprietes.PORT.getiValue());
				os = new PrintStream(clientSocket.getOutputStream());
				is = new BufferedReader(new InputStreamReader(
						clientSocket.getInputStream()));
			} catch (UnknownHostException e) {
				return "Don't know about host ";
			} catch (IOException e) {
				return "Couldn't get I/O for the connection to the host ";
			}
		}
		return "ok";
	}

	public void sendRow(String... info) {
		for (String s : info) {
			os.println(s);
		}
		os.flush();
	}

	public String getRow() {
		String line = null;
		try {
				line = is.readLine();
		} catch (IOException ex) {
			Logger.getLogger(Conect.class.getName())
					.log(Level.SEVERE, null, ex);

		}
		return line;
	}
}
